package com.bjsxt.controller;

import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bjsxt.domain.SysUserLog;
import com.bjsxt.model.Result;
import com.bjsxt.service.SysUserLogService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

/**
 * description:
 * 用户操作日志控制层
 * 用户操作日志的权限:
 * 查询: sys_user_log_query
 *
 * @author ALIENWARE <br />
 * @date 2021/7/15
 */
@RestController
@RequestMapping("/sysUserLog")
@Api(tags = "用户操作日志控制器")
public class SysUserLogController {
    /**
     * 用户操作日志业务层接口
     */
    @Autowired
    private SysUserLogService sysUserLogService;

    /**
     * 用户操作日志分页查询
     *
     * @param page 分页对象<SysUserLog>
     * @return 统一响应对象
     */
    @GetMapping
    @PreAuthorize("hasAuthority('sys_user_log_query')")
    @ApiOperation(value = "分页查询用户操作日志", authorizations = {@Authorization("Authorization")})
    @ApiImplicitParams({
            @ApiImplicitParam(name = "current", value = "当前页", dataType = "Long", paramType = "query", example = "1"),
            @ApiImplicitParam(name = "size", value = "每页条数", dataType = "Long", paramType = "query", example = "20")
    })
    public Result<Page<SysUserLog>> findByPage(@ApiIgnore Page<SysUserLog> page) {
        // 查询时间, 我们讲最近新增的, 修改的数据优先展示, 排序 created
        page.addOrder(OrderItem.desc(SysUserLog.COL_CREATED));
        // 调用业务层进行分页数据的查询
        Page<SysUserLog> sysUserPage = sysUserLogService.page(page);
        // 返回响应数据
        return Result.success(sysUserPage);
    }
}
